package cn.com.xf.dao.impl;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import cn.com.xf.dao.TblOaAuthRoleDAO;
import cn.com.xf.dao.support.XFSqlMapClientDaoSupport;
import cn.com.xf.domain.TblOaAuthRole;

@Repository
public class TblOaAuthRoleDAOImpl extends XFSqlMapClientDaoSupport implements TblOaAuthRoleDAO {

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_ROLE
	 * 
	 * @ibatorgenerated Mon Jun 15 10:37:09 GMT+08:00 2015
	 */
	public TblOaAuthRoleDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_ROLE
	 * 
	 * @ibatorgenerated Mon Jun 15 10:37:09 GMT+08:00 2015
	 */
	@Override
	public int deleteByPrimaryKey(BigDecimal roleId) {
		TblOaAuthRole key = new TblOaAuthRole();
		key.setRoleId(roleId);
		int rows = getSqlMapClientTemplate().delete("TBL_OA_AUTH_ROLE.ibatorgenerated_deleteByPrimaryKey", key);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_ROLE
	 * 
	 * @ibatorgenerated Mon Jun 15 10:37:09 GMT+08:00 2015
	 */
	@Override
	public int insert(TblOaAuthRole record) {
		return (Integer) getSqlMapClientTemplate().insert("TBL_OA_AUTH_ROLE.ibatorgenerated_insert", record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_ROLE
	 * 
	 * @ibatorgenerated Mon Jun 15 10:37:09 GMT+08:00 2015
	 */
	@Override
	public void insertSelective(TblOaAuthRole record) {
		getSqlMapClientTemplate().insert("TBL_OA_AUTH_ROLE.ibatorgenerated_insertSelective", record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_ROLE
	 * 
	 * @ibatorgenerated Mon Jun 15 10:37:09 GMT+08:00 2015
	 */
	@Override
	public TblOaAuthRole selectByPrimaryKey(BigDecimal roleId) {
		TblOaAuthRole key = new TblOaAuthRole();
		key.setRoleId(roleId);
		TblOaAuthRole record = (TblOaAuthRole) getSqlMapClientTemplate().queryForObject(
				"TBL_OA_AUTH_ROLE.ibatorgenerated_selectByPrimaryKey", key);
		return record;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_ROLE
	 * 
	 * @ibatorgenerated Mon Jun 15 10:37:09 GMT+08:00 2015
	 */
	@Override
	public int updateByPrimaryKeySelective(TblOaAuthRole record) {
		int rows = getSqlMapClientTemplate().update("TBL_OA_AUTH_ROLE.ibatorgenerated_updateByPrimaryKeySelective",
				record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method
	 * corresponds to the database table TBL_OA_AUTH_ROLE
	 * 
	 * @ibatorgenerated Mon Jun 15 10:37:09 GMT+08:00 2015
	 */
	@Override
	public int updateByPrimaryKey(TblOaAuthRole record) {
		int rows = getSqlMapClientTemplate().update("TBL_OA_AUTH_ROLE.ibatorgenerated_updateByPrimaryKey", record);
		return rows;
	}
	
	@Override
	public TblOaAuthRole selectRoleIdByRoleDesc(String roleDesc) {
		return (TblOaAuthRole) getSqlMapClientTemplate().queryForObject("TBL_OA_AUTH_ROLE.ibatorgenerated_selectRoleIdByRoleDesc", roleDesc);
	}
	
	@Override
	public List<TblOaAuthRole> selectRoleList() {
		List<TblOaAuthRole> list = getSqlMapClientTemplate()
				.queryForList("TBL_OA_AUTH_ROLE.ibatorgenerated_selectList");
		return list;
	}

	@Override
	public List<TblOaAuthRole> selectRoleList4Check(String siteId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("siteId", siteId);
		List<TblOaAuthRole> list = getSqlMapClientTemplate().queryForList(
				"TBL_OA_AUTH_ROLE.ibatorgenerated_selectList4Check", map);
		return list;
	}

	@Override
	public TblOaAuthRole selectByRoleDesc(String roleDesc) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roleDesc", roleDesc);
		List<TblOaAuthRole> list = getSqlMapClientTemplate().queryForList(
				"TBL_OA_AUTH_ROLE.ibatorgenerated_selectByRoleDesc", map);
		if (!CollectionUtils.isEmpty(list)) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public TblOaAuthRole selectByRoleDescAndSiteId(String roleDesc, String siteId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("siteId", siteId);
		map.put("roleDesc", roleDesc);
		List<TblOaAuthRole> list = getSqlMapClientTemplate().queryForList(
				"TBL_OA_AUTH_ROLE.ibatorgenerated_selectByRoleDesc", map);
		if (!CollectionUtils.isEmpty(list)) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<TblOaAuthRole> selectRoleListByQuery(String orderByField, String orderByMode, String roleDesc,
			int begin, int pageSize) {
		Map<String, Object> map = new HashMap<String, Object>();
		int end = begin + pageSize;
		begin = begin + 1;
		map.put("begin", begin);
		map.put("end", end);
		map.put("orderByField", orderByField);
		map.put("orderByMode", orderByMode);
		map.put("roleDesc", roleDesc);
		List<TblOaAuthRole> list = getSqlMapClientTemplate().queryForList(
				"TBL_OA_AUTH_ROLE.ibatorgenerated_selectRoleListByQuery", map);
		return list;
	}

	@Override
	public int selectRoleListByQueryCount(String roleDesc) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("roleDesc", roleDesc);
		return (Integer) getSqlMapClientTemplate().queryForObject(
				"TBL_OA_AUTH_ROLE.ibatorgenerated_selectRoleListByQueryCount", map);
	}

	@Override
	public TblOaAuthRole selectRoleByRoleName(String roleName) {
		Map<String, String> map = new HashMap<String, String>();
		map.put("roleName", roleName);
		List<TblOaAuthRole> list = getSqlMapClientTemplate().queryForList(
				"TBL_OA_AUTH_ROLE.ibatorgenerated_selectRoleByRoleName", map);
		if (!CollectionUtils.isEmpty(list)) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public List<TblOaAuthRole> selectRoleListByQuery4Check(String siteid, String rolename, int begin, int pageSize) {
		Map<String, Object> map = new HashMap<String, Object>();
		int end = begin + pageSize;
		begin = begin + 1;
		map.put("begin", begin);
		map.put("end", end);
		map.put("siteid", siteid);
		map.put("rolename", rolename);
		List<TblOaAuthRole> list = getSqlMapClientTemplate().queryForList(
				"TBL_OA_AUTH_ROLE.ibatorgenerated_selectRoleListByQuery4Check", map);
		return list;
	}

	@Override
	public int selectRoleListByQueryCount4Check(String siteid, String rolename) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("rolename", rolename);
		map.put("siteid", siteid);
		return (Integer) getSqlMapClientTemplate().queryForObject("TBL_OA_AUTH_ROLE.selectRoleListByQueryCount4Check",
				map);
	}

}